

from typing import *


class Solution:
    def validSubstringCount(self, word1: str, word2: str) -> int:
        c2 = Counter(word2)
        j , same,ans, r =  0,0,0, len(word1)
        c1 = Counter()
        for i,v in enumerate(word1):
            c1[v] += 1
            if c2[v]== c1[v]:
                same+=1
                while same == len(c2):
                    ans+= r - i
                    c1[word1[j]]-=1
                    if c1[word1[j]] < c2[word1[j]]:
                        same -=1
                    j+=1
        return ans
                
print(123)